// pages/mall/index.js
Page({
  data: {
    products: [
      {
        id: 1,
        name: "城旅定制徽章",
        image: "/assets/img/profile/medal.png",
        price: 29.9,
        originalPrice: 39.9,
        sales: 128,
        rating: 4.8,
        tags: ["限量", "定制", "收藏"],
        description: "城旅社区专属定制徽章，彰显你的身份"
      },
      {
        id: 2,
        name: "个性头像框",
        image: "/assets/img/profile/card.png",
        price: 19.9,
        originalPrice: 29.9,
        sales: 89,
        rating: 4.6,
        tags: ["个性", "装饰", "热门"],
        description: "让你的头像更加个性独特"
      },
      {
        id: 3,
        name: "高级滤镜包",
        image: "/assets/img/message/draw.png",
        price: 9.9,
        originalPrice: 19.9,
        sales: 256,
        rating: 4.9,
        tags: ["摄影", "滤镜", "实用"],
        description: "专业级摄影滤镜，让照片更美"
      },
      {
        id: 4,
        name: "城旅纪念T恤",
        image: "/assets/img/message/mountain.png",
        price: 79.9,
        originalPrice: 99.9,
        sales: 67,
        rating: 4.7,
        tags: ["服装", "纪念", "限量"],
        description: "城旅社区纪念版T恤，舒适透气"
      }
    ],
    categories: [
      { name: "全部", active: true },
      { name: "徽章", active: false },
      { name: "装饰", active: false },
      { name: "服装", active: false },
      { name: "数码", active: false }
    ],
    cartCount: 3
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '本地商城'
    })
  },

  onProductTap: function(e) {
    const product = e.currentTarget.dataset.product
    
    wx.showModal({
      title: product.name,
      content: `价格：¥${product.price}（原价¥${product.originalPrice}）\n销量：${product.sales}件\n评分：${product.rating}⭐\n标签：${product.tags.join('、')}\n\n${product.description}`,
      showCancel: true,
      cancelText: '关闭',
      confirmText: '立即购买',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '购买功能开发中',
            icon: 'none'
          })
        }
      }
    })
  },

  onCategoryTap: function(e) {
    const index = e.currentTarget.dataset.index
    const categories = this.data.categories.map((item, i) => {
      item.active = i === index
      return item
    })
    this.setData({ categories })
    
    wx.showToast({
      title: '筛选：' + categories[index].name,
      icon: 'none'
    })
  },

  onCartTap: function() {
    wx.showToast({
      title: '购物车功能开发中',
      icon: 'none'
    })
  },

  onSearchInput: function(e) {
    const value = e.detail.value
    if (value.trim()) {
      wx.showToast({
        title: '搜索：' + value,
        icon: 'none'
      })
    }
  }
})
